
package it.csttech.date;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.ws.rs.BeanParam;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import com.fasterxml.jackson.annotation.JsonGetter;

/**
 * OVERVIEW This class is a resource used to test date conversion according to
 * the locale
 * 
 * @author marcello.felappi
 * @author marco.dalena
 */

@Path("dat")
public class DateContainer {

	private String str1;
	private Date date;

	public DateContainer() {

	}

	public DateContainer(String str1, Date date) {

		this.str1 = str1;
		this.date = date;
	}

	public String getStr1() {

		return str1;
	}

	public void setStr1(String str1) {

		this.str1 = str1;
	}

	public Date getDate() {

		return date;
	}

	public void setDate(Date date) {

		this.date = date;
	}

	@Consumes(MediaType.APPLICATION_JSON)
	@GET
	public Response postDate(@QueryParam(value = "data") Date date) {

		return Response.ok().build();
	}

	@Path("list")
	@Consumes(MediaType.APPLICATION_JSON)
	@POST
	public Response postDate(List<Date> date) {

		return Response.ok(date).build();
	}

	@JsonGetter("dates")
	@Produces(MediaType.APPLICATION_JSON)
	@Path("list")
	@GET
	public List<Date> getDateList() {

		List<Date> list = new ArrayList<Date>();
		list.add(new Date());
		list.add(new Date());
		return list;
	}

	@GET
	@Produces(MediaType.APPLICATION_JSON)
	@Path("query/{prova}")
	public Response getDate2(
		@PathParam("prova") String prova, @QueryParam(value = "date") Date dat) {

		Response re = Response.ok(dat).build();

		return re;

	}

	@GET
	@Produces(MediaType.APPLICATION_JSON)
	@Path("pathComplex/{string}")
	public Response postComplexParam(@Valid @BeanParam ParamComplexObject param) {

		Response re = Response.ok(param).build();

		return re;

	}

	@GET
	@Produces(MediaType.APPLICATION_JSON)
	@Path("example")
	public int getExample(@NotNull @QueryParam("example") Integer intero) {

		return intero;

	}

	@GET
	@Produces(MediaType.APPLICATION_JSON)
	@Path("stringnumber")
	public int getStringNumber(@QueryParam("string") String intero) {

		return Integer.parseInt(intero);

	}

}
